<h1>Ubah Profil</h1>
<?
$disabled = (empty($model->member_bank_account_no)) ? "" : "disabled";

?>
<script language="javascript">
    var optionParent = new Array();
    var valueParent = new Array();
    var optionChild = new Array();
    var valueChild = new Array();
    var defaultChildId = '0';
    var defaultParentId = '0';

<?php
$q_parent = "SELECT area_id, area_name FROM ref_area WHERE area_par_id = '0'";
$r_parent = Yii::app()->db->createCommand($q_parent)->queryAll();
$i = 0;

foreach ($r_parent as $parent) {
    extract($parent);
    $q_child = "SELECT area_id AS id_child, area_name AS wil_child FROM ref_area WHERE area_par_id = '$area_id' ORDER BY area_name";
    $r_child = Yii::app()->db->createCommand($q_child)->queryAll();
    $arrOptionChild = "";
    $arrValueChild = "";

    foreach ($r_child as $child) {
        @extract($child);

        if ($id_child == $model->member_city_id) {
            $arrOptionChild .= "'===== $wil_child =====',";
        } else {
            $arrOptionChild .= "'$wil_child',";
        }

        $arrValueChild .= "'$id_child',";
        //$arrValueChild .= "'$wil_child',";
    }

    $arrOptionChild = substr($arrOptionChild, 0, -1);
    $arrValueChild = substr($arrValueChild, 0, -1);

    if ($area_id == $model->member_state_id) {
        ?>
                    optionParent[<?= $i ?>] = '===== <?= $area_name ?> =====';
                    valueParent[<?= $i ?>] = '<?= $area_id ?>';
        <?php
    } else {
        ?>
                    optionParent[<?= $i ?>] = '<?= $area_name ?>';
                    valueParent[<?= $i ?>] = '<?= $area_id ?>';
        <?php
    }
    ?>

            optionChild[<?= $i ?>] = Array(<?= $arrOptionChild; ?>);
            valueChild[<?= $i ?>] = Array(<?= $arrValueChild; ?>);
    <?php
    $i++;
}
?>

    function loadParent(parent, child)
    {
        if(parent.length <= 1)
        {
            parent.length = 0;
            for(var i = 0; i < optionParent.length; i++)
            {
                parent.options[i] = new Option(optionParent[i], valueParent[i]);
                if(valueParent[i] == '<?php echo function_lib::get_area_name($model->member_state_id); ?>') parent.options[i].selected = true;
            }

            //parent.options[defaultParentId].selected = true;
            loadChild(parent, child);
            //child.options[defaultChildId].selected = true;
        }
    }

    function loadChild(parent, child)
    {
        var currParent = parent.selectedIndex;

        child.length = 0;

        //if (currParent > 0)
        //{
        var currOptionChild = optionChild[currParent]; //.split(',');
        var currValueChild = valueChild[currParent]; //.split(',');

        for(var i = 0; i < currOptionChild.length; i++)
        {
            child.options[i] = new Option(currOptionChild[i], currValueChild[i]);


            //child.options[0].selected = true;
            if(currValueChild[i] == '<?php echo function_lib::get_area_name($model->member_city_id); ?>') child.options[i].selected = true;
        }
        //}
    }

    var sval = '';
</script>
<div class="add">
    <form action="" method="post" name="sys_member" enctype="multipart/form-data">
        <table cellpadding="0" cellspacing="0" border="0">
            <tr class="title">
                <th colspan="2" style="text-align:left;"><strong>DATA PRIBADI</strong></th>
            </tr>
            <tr>
                <th width="100">Nama</th>
                <td><input type="text" name="sys_member[member_name]" value="<?php echo $model->member_name; ?>" size="40" class="text" /></td>
            </tr>
            <tr>
                <th>Nickname</th>
                <td><input type="text" name="sys_member[member_nickname]" value="<?php echo $model->member_nickname; ?>" size="20" class="text" /></td>
            </tr>
            <tr>
                <th>E-mail</th>
                <td><input type="text" name="sys_member[member_email]" value="<?php echo $model->member_email; ?>" size="40" class="text" /></td>
            </tr>
            <tr>
                <th>Alamat</th>
                <td><input type="text" name="sys_member[member_address]" value="<?php echo $model->member_address; ?>" size="80" class="text" /></td>
            </tr>
            <tr>
                <th>Propinsi</th>
                <td>
                    <select name="sys_member[member_state_id]" id="inputParent" onchange="loadChild(this, document.sys_member.inputChild);" onFocus="loadParent(this, document.sys_member.inputChild)">
                        <option value="<?php echo $model->member_state_id; ?>">===== <?php echo function_lib::get_area_name($model->member_state_id); ?> =====</option>
                    </select>
                </td>
            </tr>
            <tr>
                <th>Kota / Kabupaten</th>
                <td>
                    <select name="sys_member[member_city_id]" id="inputChild">
                        <option value="<?php echo $model->member_city_id; ?>">===== <?php echo function_lib::get_area_name($model->member_city_id); ?> =====</option>
                    </select>
                </td>
            </tr>
            <tr>
                <th>Kode Pos</th>
                <td><input type="text" name="sys_member[member_zipcode]" value="<?php echo $model->member_zipcode; ?>" size="5" class="text" /></td>
            </tr>
            <tr>
                <th>Tempat Lahir</th>
                <td><input type="text" name="sys_member[member_birth_place]" value="<?php echo $model->member_birth_place; ?>" size="40" class="text" /></td>
            </tr>
            <tr>
                <th>Tanggal Lahir</th>
                <td>
                    <?php
                    $this->widget('zii.widgets.jui.CJuiDatePicker', array(
                        'model' => $model,
                        'attribute' => 'member_birth_date',
                        'options' => array(
                            'yearRange'=>'-80:+0',
                            'showAnim' => 'fold',
                            'dateFormat' => 'yy-mm-dd', // save to db format
                            'altField' => '#self_pointing_id',
                            'altFormat' => 'yy-mm-dd', // show to user format
                            'changeYear' => true,
                        ),
                        'htmlOptions' => array(
                            'style' => 'padding:3px 4px;',
                            'size' => 10,
                        ),
                    ));
                    ?>
                </td>
            </tr>
            <tr>
                <th>Jenis Kelamin</th>
                <td>
                    <?php
                    $member_sex_option = array('male' => 'Laki-laki', 'female' => 'Perempuan');
                    echo CHtml::radioButtonList('sys_member[member_sex]', $model->member_sex, $member_sex_option, array('separator' => '&nbsp;&nbsp;&nbsp;'));
                    ?>
                </td>
            </tr>
            <tr>
                <th>No. Identitas</th>
                <td>
                    <?php
                    $member_identity_type_option = array('ktp' => 'KTP', 'sim' => 'SIM', 'passport' => 'Passport');
                    echo CHtml::radioButtonList('sys_member[member_identity_type]', $model->member_identity_type, $member_identity_type_option, array('separator' => '&nbsp;&nbsp;&nbsp;'));
                    ?>
                    &nbsp;&nbsp;&nbsp;<input type="text" name="sys_member[member_identity_no]" value="<?php echo $model->member_identity_no; ?>" size="20" maxlength="30" class="text" />
                </td>
            </tr>
            <tr>
                <th>No. Telepon</th>
                <td><input type="text" name="sys_member[member_phone]" value="<?php echo $model->member_phone; ?>" size="20" class="text" /></td>
            </tr>
            <tr valign="top">
                <th>No. Handphone</th>
                <td><input type="text" name="sys_member[member_mobilephone]" value="<?php echo $model->member_mobilephone; ?>" size="20" class="text" disabled /><br /><small><i>(untuk mengganti nomor handphone, silakan hubungi admin kami)</i></small></td>
            </tr>
            <tr>
                <th>Foto</th>
                <td>
                    <?php
                    if ($model->member_image != '' && file_exists(Yii::app()->params['config']['updir']['member'] . $model->member_image))
                        echo '<div style="margin-bottom:5px;">' . CHtml::image(Yii::app()->params['config']['dir']['member'] . $model->member_image, (($model->member_image != null) ? $model->member_image : ''), array('width' => 75, 'style' => 'border:1px solid #ccc; padding:3px;')) . '</div>';
                    ?>
                    <input type="file" name="sys_member[member_image]" size="30" class="file" /><br><small><i>(ukuran terbaik 75px x 75px)</i></small>
                </td>
            </tr>
            <tr class="title">
                <th colspan="2" style="text-align:left;"><strong>DATA PEWARIS</strong></th>
            </tr>
            <tr>
                <th>Nama</th>
                <td><input type="text" name="sys_member[member_devisor_name]" value="<?php echo $model->member_devisor_name; ?>" size="40" class="text" /></td>
            </tr>
            <tr>
                <th>Hubungan</th>
                <td><input type="text" name="sys_member[member_devisor_relationship]" value="<?php echo $model->member_devisor_relationship; ?>" size="40" class="text" /></td>
            </tr>
            <tr>
                <th>No. Telepon</th>
                <td><input type="text" name="sys_member[member_devisor_phone]" value="<?php echo $model->member_devisor_phone; ?>" size="40" class="text" /></td>
            </tr>
            <tr class="title">
                <th colspan="2" style="text-align:left;"><strong>DATA BANK</strong> <small><i>(untuk mengganti data bank, silakan hubungi admin kami)</i></small></th>
            </tr>
            <tr>
                <th>Nama Bank</th>
                <td>
                    <?php
                    echo CHtml::activeDropDownList($model, 'member_bank_id', CHtml::listData(ref_bank::model()->findAll("bank_is_active = '1'"), 'bank_id', 'bank_name'));
                    ?>
                </td>
            </tr>
            <tr>
                <th>Kota Bank</th>
                <td><input type="text" name="sys_member[member_bank_city]" value="<?php echo $model->member_bank_city; ?>" size="40" class="text" <?php echo $disabled;?> /></td>
            </tr>
            <tr>
                <th>Cabang</th>
                <td><input type="text" name="sys_member[member_bank_branch]" value="<?php echo $model->member_bank_branch; ?>" size="40" class="text" <?php echo $disabled;?> /></td>
            </tr>
            <tr>
                <th>Nama Nasabah</th>
                <td><input type="text" name="sys_member[member_bank_account_name]" value="<?php echo $model->member_bank_account_name; ?>" size="40" class="text" <?php echo $disabled;?> /></td>
            </tr>
            <tr>
                <th>Nomor Rekening</th>
                <td><input type="text" name="sys_member[member_bank_account_no]" value="<?php echo $model->member_bank_account_no; ?>" size="40" class="text" <?php echo $disabled;?> /></td>
            </tr>
            <tr class="title">
                <th colspan="2" style="text-align:left;"><strong>Auto Withdrawal</strong><small><i>(Apakah bonus anda akan ditransfer otomatis setelah mencapai 500.000 ?)</i></small></th>
            </tr>
            <tr>
                <th>Set Auto </th>
                <td>
                    <?php
                    $auto_withdrawal = array('0' => 'Tidak', '1' => 'Ya');
                    echo CHtml::radioButtonList('sys_member[member_is_auto_withdrawal]', $model->member_is_auto_withdrawal, $auto_withdrawal, array('separator' => '&nbsp;&nbsp;&nbsp;'));
                    ?>
                </td>
            </tr>
            <tr class="title">
                <th colspan="2" style="text-align:left;"><strong>VALIDASI PIN</strong></th>
            </tr>
            <tr>
                <th>PIN</th>
                <td><input type="password" name="pin" value="" size="10" class="text" /></td>
            </tr>
            <tr>
                <th>&nbsp;</th>
                <td><input type="submit" name="edit" value="Simpan" class="button" /></td>
            </tr>
        </table>
    </form>
</div>